package com.yh.tea.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yh.tea.entity.Resource;
import com.yh.tea.service.ResourceService;
import com.yh.tea.utiity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2024-03-04
 */
@RestController
@CrossOrigin
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;
    @PostMapping("/getMenu")
    public ResponseResult getMenu(@RequestBody  List<Long> resourceIdList){
        return resourceService.getMenu(resourceIdList);
    }
    @GetMapping("/getResourceCascader")
    public ResponseResult  getResourceCascader(){
        return resourceService.getResourceCascader();
    }
    @GetMapping("/getResource")
    public ResponseResult  getResource(){
        return resourceService.getResource();
    }
    @PostMapping("/addResource")
    public ResponseResult addResource(@RequestBody Resource resource){
        Boolean result=resourceService.save(resource);
        return ResponseResult.success(result?"添加成功":"添加失败",result);
    }
    @PostMapping("/delResource")
    public ResponseResult delResource(@RequestBody List<Long> resourceIdList){
        Boolean result=resourceService.removeBatchByIds(resourceIdList);
        return ResponseResult.success(result?"删除成功":"删除失败",result);
    }
    @PostMapping("/updateResource")
    public ResponseResult updateResource(@RequestBody Resource resource){
        Boolean result=resourceService.update(resource,new QueryWrapper<Resource>().eq("id",resource.getId()));
        return ResponseResult.success(result?"修改成功":"修改失败",result);
    }
}

